<!-- <! [CDATA [
if (top.location != self.location) {
	top.location.replace(self.location);
}
//document.onError = function { alert('A aparut o eroare in Javascript la pornirea site-ului. Contactati administratorul.'); };

function initializare() {
	//Functie executata la aparitia evenimentului body:onload.
	setare_variabile();
	reimprospatare('');
	incarcare_foaieStil();
	initializare_drag();
	motor_notificari();
	var ora_1 = document.getElementById("ora_server").innerHTML;
	var minut_1 = document.getElementById("minut_server").innerHTML;
	var secunda_1 = document.getElementById("secunda_server").innerHTML;
	timp_server(ora_1, minut_1, secunda_1);
	returnare_planete();
	//setTimeout("incarcare_imagini();", 5000);
}

function setare_variabile() {
	document.getElementById('pull_down_menu_1').style.top = -35 + "px";
	document.getElementById('pull_down_menu_2').style.left = -200 + "px";
	document.getElementById('hint_frame').style.display = "none";
	t = false;
	t_1 = false;
	t_2 = false;
	t_3 = false;
	t_4 = false;
	u_1 = false;
	u_2 = false;
	u_3 = false;
	u_4 = false;
	u_5 = false;
	u_6 = false;
	u_7 = false;
	u_8 = false;
	t_m = false;
	t_g = false;
	t_a_p = false;
	t_a_t = false;
	t_a = false;
	t_o = false;
	actiune_frame_act_1_count = false;
	actiune_frame_act_2_count = false;
	actiune_frame_act_3_count = false;
	actiune_frame_act_4_count = false;
	unitati_actiuni_act_1_count = false;
	unitati_actiuni_act_2_count = false;
	unitati_actiuni_act_3_count = false;
	unitati_actiuni_act_4_count = false;
	unitati_actiuni_act_5_count = false;
	unitati_actiuni_act_6_count = false;
	unitati_actiuni_act_7_count = false;
	unitati_actiuni_act_8_count = false;
	unitati_actiuni_act_9_count = false;
	unitati_actiuni_act_10_count = false;
	unitati_actiuni_act_11_count = false;
	unitati_actiuni_act_12_count = false;
	timp_raspuns_notificari = 0;
	notificari_atac_primit_count = false;
	notificari_atac_trimis_count = false;
	notificari_intarire_count = false;
	notificari_intoarcere_count = false;
}

function motor_notificari() {
	returnare_notificari();
	if (timp_raspuns_notificari>0)
	{
	if (timp_raspuns_notificari*100<10)
	  timp_raspuns_notificari = 5/100;
	 setTimeout("motor_notificari()", timp_raspuns_notificari*100*1000*2);
	}
	else
	 setTimeout("motor_notificari()", 10000);
}

function incarcare_continut() {
	var ultimul_frame = citire_cookie('ultimulFrame');
	switch (ultimul_frame) {
		case 'planeta':
	 returnare_planeta();
	    break;
		case 'harta':
	 returnare_harta(0,0);
	 	break;
	 	case 'statistici':
	 returnare_statistici('utilizatori', '');
	 	break;
	 	case 'mesaje':
	 returnare_mesaje('primite', '0');
	    break;
		case 'instructiuni':
	 returnare_planeta();
	 	break;
		default:
	 returnare_planeta();
	 	break;
	}
}

function timp_server(ora, minut, secunda) {
	var date = new Date();
	date.setHours(ora);
	date.setMinutes(minut);
	date.setSeconds(secunda);
		
	document.getElementById("ora_server").innerHTML = date.getHours();
	document.getElementById("minut_server").innerHTML = date.getMinutes();
	document.getElementById("secunda_server").innerHTML = date.getSeconds();
	
	setTimeout("timp_server("+date.getHours()+","+date.getMinutes()+","+date.getSeconds()+"+1);", 1000);
}

function incarcare_foaieStil() {
	var browser = detectareBrowser();
	if (browser == "net") 
	 browser = "other";
	links = document.getElementsByTagName("link");
	for (i=0; i<links.length; i++) {
		thisLink = links[i];
		if (thisLink.getAttribute("rel").indexOf("style") > -1 && thisLink.getAttribute("title")) {
			thisLink.disabled = true;
			if (thisLink.getAttribute("title") ==  browser)
			 thisLink.disabled = false;
		}
	}
}

function schimba_disable() {
	blocareFrame = document.getElementById("blocare_frame").style;
	if (blocareFrame.display == "block") 
	 blocareFrame.display = "none";
	else 
	 blocareFrame.display = "block";
}

function citire_cookie(id) {
	thisCookie = document.cookie.split("; ");
	for (i=0; i<thisCookie.length; i++) {
		if (id == thisCookie[i].split("=")[0]) {		
			return thisCookie[i].split("=")[1];
		}
	} 
}

function setare_cookie(id, nume) {
 	var acum = new Date();
    acum.setTime( acum.getTime() );
    var dataExpirare = new Date( acum.getTime() + 1000 * 60 * 60 * 24 );
	if (document.cookie != "") {
		document.cookie = id+"="+nume+";expires="+dataExpirare.toGMTString();
	}
}

function incarcareAJAX(stare) {
	if(stare == "activ")
	 document.getElementById('incarcare_frame').style.display = "block";
	else
	 document.getElementById('incarcare_frame').style.display = "none";
}

function countdown(obiect, secunde) {
	eval(obiect+"_count = true");
	if (secunde >= 0)
	{
     h = Math.floor(secunde / 3600);
     m = Math.floor((secunde - (h*3600)) / 60);
     s = secunde - (h*3600) - (m*60);
	 if (h <= 9)
	  h = '0'+h;  
	 if (m <= 9)
	  m = '0'+m; 
	 if (s <= 9)
	  s = '0'+s; 
	 eval("status_count = "+obiect+"_count");
	 if (document.getElementById(obiect) && status_count)
	  {
	 document.getElementById(obiect).innerHTML = h+":"+m+":"+s;
	 secunde--;
	 eval(obiect+"_count = setTimeout(\"countdown('"+obiect+"', "+secunde+")\", 1000)");
	 //alert(eval(obiect+"_count"));
	  }
   }
}

function countup(obiect, secunde) {
	if (secunde >= 0)
	{
     h = Math.floor(secunde / 3600);
     m = Math.floor((secunde - (h*3600)) / 60);
     s = secunde - (h*3600) - (m*60);
	 if (h <= 9)
	  h = '0'+h;  
	 if (m <= 9)
	  m = '0'+m; 
	 if (s <= 9)
	  s = '0'+s; 
	 if (document.getElementById(obiect))
	  {
	 document.getElementById(obiect).innerHTML = h+":"+m+":"+s;
	 secunde++;
	 setTimeout("countup('"+obiect+"', "+secunde+")", 1000);
	  }
   }
}

function stergere_multipla_mesaje(mod) {
    k = 0;
	vector = new Array;
	if (mod == "primite")
		checkSet = document.mesaje_primite.check_primite;
    else if (mod == "trimise")
		checkSet = document.mesaje_trimise.check_trimise;		
   if (checkSet.checked)	 
    return "1@"+checkSet.value+"@";
	else {
	 for (i=0; i<checkSet.length; i++)
			  if (checkSet[i].checked)
			  { 
			   vector[k] = checkSet[i].value;
			   k++;
			  }  		  
	 sir = k+'@';
	 for (j=0;j<k;j++)
	 	sir += vector[j]+'@';
	return sir;
	}
}

function selectare_multipla_mesaje(mod) {
	if (mod == "primite")
		checkSet = document.mesaje_primite.check_primite;
    else if (mod == "trimise")
		checkSet = document.mesaje_trimise.check_trimise;		
   if (checkSet.checked)	 
	 checkSet.checked = !(checkSet.checked);
	else {
	 for (i=0; i<checkSet.length; i++)
			   checkSet[i].checked = !(checkSet[i].checked);
	}
}

function returnare_optiuni() {
	k = 0;
	vector = new Array;
	checkSet = document.optiuni_1.optiuni_value;  
	checkMax = document.optiuni_1.optiuni_max;
	if (checkSet.value)
	{
	 x = parseInt(checkSet.value);
	 y = parseInt(checkMax.value);
      if  (x == '')
	  x = 0;
	  if (x > y) {
	  if (y < 0)
	  y = 0;
	  checkSet.value = y;
      return false;
	  } else
	  return "1@"+x+"@";
	}
    else 
	{
	 for (i=0; i<checkSet.length; i++)
			 {
			   x = parseInt(checkSet[i].value);
			   y = parseInt(checkMax[i].value);
			   if (x == '')
			    x = '0';
			   if (x > y) {
			   if (y < 0)
	            y = 0;
			   checkSet[i].value = y;
			   return false;
			   } else {
			   vector[k] = x;
			   k++;
			   }
			  }
	 sir = k+'@';
	 for (j=0;j<k;j++)
	 	sir += vector[j]+'@';
	return sir;
	}
}

function returnare_expediere() {
	k = 0;
	sir = '';
	validare = true;
	vector = new Array;
	inputSet1 = document.expediere_form.expediere_unitati_tip;
	inputSet2 = document.expediere_form.expediere_unitati_numar;  
	inputSet3 = document.expediere_form.expediere_numar_max;
	if (inputSet1.value && inputSet2.value)
	{
	 x = inputSet1.value;	
	 y = inputSet2.value;
     if  (x == '')
	  x = 0;
	 if  (y == '')
	  y = 0;
	 if (y > inputSet3.value) { 				 
	  inputSet2.value = inputSet3.value;
	  return 'false';
	 }
	 return x+"x"+y;
	}
    else 
	{
	 for (i=0; i<inputSet1.length; i++)
			  {
			   x = inputSet1[i].value;
			   y = inputSet2[i].value;
			   if (x == '')
			    x = '0';
		       if (y == '')
			    y = '0';
			   if (y > inputSet3[i].value) {
	             inputSet2[i].value = inputSet3[i].value;
				 inputSet2[i].select();
				 validare = false;
			   }
			   vector[k] = x+"x"+y;
			   k++;
			  }
	 for (j=0;j<k;j++)
	 if (j==k-1)
	  sir += vector[j];
		else
	  sir += vector[j]+'s';
	if ((document.expediere_form.coord_x.value == '0') || (document.expediere_form.coord_y.value == '0')) {
	 fereastra("Nu ati introdus coordonate valide!");
	 validare = false;
	}
	if ((validare)) 				
	return sir;
	 else
	return 'false';
	}
}

function schimba_planeta(id) {
	returnare_ajax('librarie/php/op_planeta.php?id='+id, 'schimba_planeta');
}

function returnare_planete() {
	returnare_ajax('librarie/php/op_planeta.php', 'returnare_planete');
}

function optiuni_structura(id, mod) {
	reimprospatare('resurse');
	reimprospatare('unitati');
	switch (mod) {
	case '':
	 returnare_ajax("librarie/php/status_cladiri.php?id="+id, 'optiuni', '');
	break;
	case 'string':
	 string = returnare_optiuni();
	if (string) {
	 returnare_ajax("librarie/php/status_cladiri.php?id="+id+"&string="+string, 'optiuni', ''); 
	} else 
	 fereastra('Nu aveti destule resurse sau loc liber.');
	break;
	case 'expediere':
	 unitati = returnare_expediere();
	 if (unitati == 'false')
	  return false;
	 box = document.expediere_form.tip_expediere;
	 tip_expediere = box.options[box.selectedIndex].value;
	 coord = document.expediere_form.coord_x.value+"-"+document.expediere_form.coord_y.value;
	 returnare_ajax("librarie/php/cladiri/confirmare_expeditie.php?tip="+tip_expediere+"&unitati="+unitati+"&coord="+coord, 'optiuni', '');
	break;
	case 'repartizare_rafinarie_gaz':
	 box = document.repartizare_rafinarie_gaz.tip_detasare;
	 var nr_max = document.repartizare_rafinarie_gaz.muncitori_liberi;
	 var nr_selectati = document.repartizare_rafinarie_gaz.nr_muncitori_selectati;
	 var muncitori_repartizati = document.repartizare_rafinarie_gaz.muncitori_repartizati;
	 var tip = box.options[box.selectedIndex].value;
	 var valid = true;
	  if (nr_selectati.value == '' || nr_selectati.value == '0' || nr_selectati.value < 0 || isNaN(nr_selectati.value)) {
	    nr_selectati.value = nr_max.value;
		valid = false;
	  }
	  if (tip == 'antrenare') {
	    if (parseInt(nr_selectati.value) > parseInt(nr_max.value)) {
	   fereastra('Nu aveti destui muncitori nerepartizati!');
	   nr_selectati.value = nr_max.value;
	   valid = false;
	    } 
	  } else { 
	  if (tip == 'detasare')
	   if (parseInt(nr_selectati.value) > parseInt(muncitori_repartizati.value)) {
	   fereastra('Nu aveti destui muncitori in repartizati!');
	   nr_selectati.value = muncitori_repartizati.value;
	   valid = false;
	   }	  
	  }
	  
	  if (valid) {
	   var param = nr_selectati.value+'@'+tip;
	   returnare_ajax("librarie/php/status_cladiri.php?id="+id+"&nr_rep_gaz="+param, 'optiuni', '');
	  }
	break;
    case 'repartizare_rafinarie_minerale':
	 box = document.repartizare_rafinarie_minerale.tip_detasare;
	 var nr_max = document.repartizare_rafinarie_minerale.muncitori_liberi;
	 var nr_selectati = document.repartizare_rafinarie_minerale.nr_muncitori_selectati;
	 var muncitori_repartizati = document.repartizare_rafinarie_minerale.muncitori_repartizati;
	 var tip = box.options[box.selectedIndex].value;
	 var valid = true;
	  if (nr_selectati.value == '' || nr_selectati.value == '0' || nr_selectati.value < 0 || isNaN(nr_selectati.value)) {
	    nr_selectati.value = nr_max.value;
		valid = false;
	  }
	  if (tip == 'antrenare') {
	    if (parseInt(nr_selectati.value) > parseInt(nr_max.value)) {
	   fereastra('Nu aveti destui muncitori nerepartizati!');
	   nr_selectati.value = nr_max.value;
	   valid = false;
	    } 
	  } else { 
	  if (tip == 'detasare')
	   if (parseInt(nr_selectati.value) > parseInt(muncitori_repartizati.value)) {
	   fereastra('Nu aveti destui muncitori in repartizati!');
	   nr_selectati.value = muncitori_repartizati.value;
	   valid = false;
	   }	  
	  }
	  
	  if (valid) {
	   var param = nr_selectati.value+'@'+tip;
	   returnare_ajax("librarie/php/status_cladiri.php?id="+id+"&nr_rep_minerale="+param, 'optiuni', '');
	  }
	break;
	default:
     returnare_ajax("librarie/php/status_cladiri.php?id="+id+"&anulare="+mod, 'optiuni', '');
	break;
	}
	reimprospatare('resurse');
	reimprospatare('unitati');
}

function optiuni_utilizator(id) {
	 returnare_ajax("librarie/php/status_utilizator.php?id="+id, 'optiuni', '');
}

function trateaza_mesaj() {
	var utilizator = document.compune_mesaj.destinatar;
	if (utilizator.value != '')
	 returnare_ajax("librarie/php/verificare_date.php?utilizator="+utilizator.value, 'verificare_date', 'trateaza_mesaj');
}

function trimite_mesaj() {
	destinatar = document.compune_mesaj.destinatar;
	subiect = document.compune_mesaj.subiect;
	mesaj = document.compune_mesaj.mesaj;
	eroare = null;
	 if (destinatar.value == '') {
	  eroare = 'Introduceti destinatarul mesajului!';
	 }
	 if (subiect.value == '') {
	  subiect_2 = 'Fara subiect';
	 } else subiect_2 = subiect.value;
	 if (mesaj.value == '') {
	  eroare = 'Mesajul este gol!';
	 }
	 
	 if (eroare != null)
	  fereastra(eroare);
	 else
	  returnare_mesaje('trimite', destinatar.value+'@'+subiect_2+'@'+mesaj.value)
}

function ascunde_element(obiect) {
	var element = document.getElementById(obiect).style;
	 if (element.display == "block")
	element.display = "none";
}

function detectareBrowser() {
	browser = "other";
	if (navigator.appName == "Netscape") {
		browser = "net";
	} else if (navigator.appName == "Microsoft Internet Explorer") {
			browser = "ie";
	}
	return browser;
}

function schimba_continut(frame) {
	switch (frame)
	{
		case 'planeta':
		document.getElementById('continut_frame').innerHTML = document.getElementById(frame+'_continut_frame').innerHTML;
		break;
		case 'harta':
		document.getElementById('continut_frame').innerHTML = document.getElementById(frame+'_continut_frame').innerHTML;
		break;
		case 'statistici':
		document.getElementById('continut_frame').innerHTML = document.getElementById(frame+'_continut_frame').innerHTML;
		break;
		case 'mesaje':
		document.getElementById('continut_frame').innerHTML = document.getElementById(frame+'_continut_frame').innerHTML;
		break;
		case 'instructiuni':
		document.getElementById('continut_frame').innerHTML = document.getElementById(frame+'_continut_frame').innerHTML;
		break;
		default:
 	    fereastra("BUG: functii.js - schimbare_continut function...");
	    break;		
	}
}

function hint(obiect, id, e) {
	if (detectareBrowser() ==  "ie" && document.getElementById('hint_frame')) {
	document.getElementById('hint_frame').style.left = event.clientX+20; 
	document.getElementById('hint_frame').style.top = event.clientY+20;
	document.getElementById('hint_frame').style.display = "block";
	document.getElementById('hint_frame').innerHTML = obiect+'<br>'+id;
	} else
	if (detectareBrowser() == "net" && document.getElementById('hint_frame')) {
	document.getElementById('hint_frame').style.left = e.pageX+20; 
	document.getElementById('hint_frame').style.top = e.pageY+20;
	document.getElementById('hint_frame').style.display = "block";
	document.getElementById('hint_frame').innerHTML = obiect+'<br>'+id;	
	} else 
	if (document.getElementById('hint_frame')) {	
	document.getElementById('hint_frame').style.left = e.pageX+20+ "px"; 
	document.getElementById('hint_frame').style.top = e.pageY+20+ "px";
	document.getElementById('hint_frame').style.display = "block";
	document.getElementById('hint_frame').innerHTML = obiect+'<br>'+id;	
			}
}

function hint_hide() {
	if (document.getElementById('hint_frame'))
	 document.getElementById('hint_frame').style.display = "none";
}

function universal_frame(text, left, top, extraParam) {
	if (extraParam == "inchidere")
	 document.getElementById('universal_frame').style.display = "none";
	else {
	 frame = '<div style="float: right"><a href="javascript:void(0)" onClick="javascript:universal_frame(\'\', \'\', \'\', \'inchidere\')" >x</a></div>';
	 document.getElementById('universal_frame').style.display = "block";
	 document.getElementById('universal_frame').innerHTML = frame+text;
	 }
}

function status(obiect) {   
	returnare_ajax('librarie/php/status.php?obiect='+obiect+'&mod=status', 'status', '');	
	//returnare_ajax('librarie/php/status.php?obiect='+obiect+'&mod=cerinte', 'cerinte', '');	
}

function status_planeta(coord_x, coord_y) {
	returnare_ajax('librarie/php/status_planeta.php?coord_x='+coord_x+'&coord_y='+coord_y, 'status_planeta', '');
}

function crestere_minerale(cantitate, timp) {
	if (timp < 0)
	 fereastra('BUG - functii.js crestere_minerale function...');
    if (t_m)
     clearTimeout(t_m);
document.getElementById('resurse_minerale').innerHTML = cantitate;
cantitate++;
if (timp != 0)
 t_m = setTimeout("crestere_minerale(" + cantitate + ", "+timp+");", timp*1000);	
}

function crestere_gaz(cantitate, timp) {
	if (timp < 0)
	 fereastra('BUG - functii.js crestere_resurse function...');
	if (t_g)
     clearTimeout(t_g);
document.getElementById('resurse_gaz').innerHTML = cantitate;
cantitate++;
if (timp != 0)
 t_g = setTimeout("crestere_gaz(" + cantitate + ", "+timp+");", timp*1000);
}

function reimprospatare(frame) {
switch (frame)
 {
case 'actiune':
  returnare_actiuni();
break;
case 'unitati':
  returnare_actiuni_unitati();
break;
case 'resurse':
  returnare_resurse();
break;
case 'status':
  void(0); 
break;
case 'planeta':
  returnare_planeta();
break;
case 'harta':
  returnare_harta();
break;
case 'productie':
  returnare_productie();
break;
default:
	returnare_actiuni();
	returnare_actiuni_unitati();
	returnare_actiuni_globale();
	returnare_resurse();
	returnare_energie();
    returnare_productie();  
	document.getElementById('status_frame').innerHTML = '<img src="img/logo.gif" />';
	incarcare_continut();
break;
 } 
}

function tratare_statistici(mod) {
	switch(mod) {
		case 'pozitie':
		 //document.statistici_form.user.disabled = true;
		 document.statistici_form.user.value = '';
		break;
		case 'user':
		 //document.statistici_form.pozitie.disabled = true;
		 document.statistici_form.pozitie.value = '';
		break;
		default:
		 fereastra('BUG: functii.js - tratare_statistici() function');
		break;
	}
}

function construire_frame(obiect, santier) {
	returnare_ajax('librarie/php/construire.php?obiect='+obiect, 'construire', santier);
}

function actiuni(id, tip, santier, obiect) {
	if (tip == 'anulare') {
	 returnare_ajax('librarie/php/actiuni.php?id='+id+'&cerere='+tip+'&santier='+santier+'&obiect='+obiect, 'actiune', '');   
	 fereastra('Actiunea a fost anulata.');
	 reimprospatare('resurse');
	 reimprospatare('planeta');
	}
	else
	 returnare_ajax('librarie/php/actiuni.php?id='+id+'&cerere='+tip+'&santier='+santier+'&obiect='+obiect, 'actiune', '');	
	 reimprospatare('resurse');
	 reimprospatare('planeta');
}

//functie restrictionare click 
function clickIE() { 
 if (document.all) { 
 reimprospatare_status(); 
 return false; 
 } 
}

function statistici_cautare() {
	user = document.statistici_form.user.value;
	pozitie = document.statistici_form.pozitie.value;
	eroare = null;
	if (pozitie != '') {
		if (isNaN(pozitie))
		 eroare = 'Pozitia trebuie sa fie numerica!';
	 tip = 'rang';
	 id = pozitie;
	} 

	if (user != '') {
		if (!isNaN(user)) 
		 eroare = 'Numele de utilizator nu trebuie sa fie numeric!';
	 tip = 'user';
	 id = user;
	} 
	
	if (user == '' && pozitie == '')
	 eroare = 'Introduceti un criteriu de cautare!';
	 
	if (user != '' && pozitie != '')
	 eroare = 'Introduceti doar un criteriu de cautare!';
	 
	if (eroare != null)
	 fereastra(eroare);
	else
	 returnare_statistici(tip, id);
}

function clickNS(e) {
if (document.layers||(document.getElementById&&!document.all)) {  
 if (e.which==1||e.which==3) return false; 
 } 
} 

if (document.layers) 
{
document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS;
} else {
document.onmouseup=clickNS; document.oncontextmenu=clickIE; 
} 
document.oncontextmenu=new Function("reimprospatare(''); return false;");

function disableselect(e) {
return false;
} 

function reEnable() {
return true;
} 

//document.onselectstart=new Function ("return false") 
//if (window.sidebar){
//document.onmousedown=disableselect
//document.onclick=reEnable
// }

function clear() {
	document.getElementById("fereastra_frame").style.display = "none";
    document.getElementById("fereastra_frame").innerHTML = '';	
}
	
function fereastra(str) {
	document.getElementById("fereastra_frame").innerHTML = str;
    document.getElementById("fereastra_frame").style.display = "block";
	setTimeout("clear()", 1500);
}

function arata_meniu() {
	if (document.getElementById) 
	          {
				meniuFrame = document.getElementById('meniu_frame').style;
				if (meniuFrame.display == "block") {
					meniuFrame.display = "none";
					schimba_disable();
				}
				else {
					meniuFrame.display = "block";
					schimba_disable();
				}
	    }
}
// ]]> -->